package me.zhengjie.modules.dqhrm.util;

import com.fasterxml.jackson.annotation.JsonValue;

public enum Gender { // 性别
    W("0","女"),B("1","男");

    private String code;
    private String sName;

    Gender(String code,String sName) {
        this.code = code;
        this.sName = sName;
    }

    public String getCode() {
        return code;
    }

    public String findByCode(String code) {
        for (Gender gender : Gender.values()) {
            if (gender.getCode().equals(code)) {
                return gender.getsName();
            }
        }
        return null;
    }

    public String findByName(String sName) {
        for (Gender gender : Gender.values()) {
            if (gender.getsName().equals(sName)) {
                return gender.getCode();
            }
        }
        return null;
    }
    public String getCodeByName(String sName) {
        for (Gender gender : Gender.values()) {
            if (gender.getsName().equals(sName)) {
                return gender.getCode();
            }
        }
        return null;
    }

    /**
     * 将数据库查询到编码自动转为文字返回给前端
     */
    @JsonValue
    public String getsName() {
        return sName;
    }
}

